package com.bsoft.config;


import com.bsoft.webservice.EntranceWebService;
import com.bsoft.webservice.impl.EntranceWebServiceImpl;
import org.apache.cxf.Bus;
import org.apache.cxf.bus.spring.SpringBus;
import org.apache.cxf.jaxws.EndpointImpl;
import org.apache.cxf.transport.servlet.CXFServlet;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;

import javax.xml.ws.Endpoint;
//http://10.254.8.18:8050/bsoft/bsoft/EntranceWebService?wsdl
@Configuration
public class WSConfig {

    @Bean(name = Bus.DEFAULT_BUS_ID)
    public SpringBus springBus() {
        return new SpringBus();
    }


    @Bean
    public EntranceWebService entranceWebService(){
        return new EntranceWebServiceImpl();
    }



    @Bean
    public ServletRegistrationBean  cxfDispatcherServlet() {
        return new ServletRegistrationBean(new CXFServlet(), "/bsoft/*");
    }
    @Bean
    public ServletRegistrationBean restServlet() {
        //注解扫描上下文
        AnnotationConfigWebApplicationContext applicationContext = new AnnotationConfigWebApplicationContext();
        //项目包名
        applicationContext.scan("com.bsoft.controller.JSON","com.bsoft.controller.XML");
        DispatcherServlet rest_dispatcherServlet = new DispatcherServlet(applicationContext);
        ServletRegistrationBean registrationBean = new ServletRegistrationBean(rest_dispatcherServlet);
        registrationBean.setLoadOnStartup(1);
        registrationBean.addUrlMappings("/*");
        return registrationBean;
    }


    @Bean
    public Endpoint endpoint1() {
        EndpointImpl endpoint = new EndpointImpl(springBus(), entranceWebService());
        endpoint.publish("/EntranceWebService");
//        endpoint.getInInterceptors().add(interfaceInLogInterceptor);//添加校验拦截器
//        endpoint.getOutInterceptors().add(interfaceOutLogInterceptor);//添加校验拦截器

        return endpoint;
    }



}
